package com.hee.erp.modules.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hee.erp.common.R;
import com.hee.erp.modules.entity.BusCustomer;
import com.hee.erp.modules.entity.BusCustomerVisit;
import com.hee.erp.modules.service.IBusCustomerService;
import com.hee.erp.modules.service.IBusCustomerVisitService;
import com.hee.erp.vo.CommonListPageParamsVo;
import com.hee.erp.vo.CustomerListParamsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author weizehong
 * @since 2022-04-16
 */
@RestController
@RequestMapping("/modules/busCustomer")
@Api(tags = "BusCustomerController")
public class BusCustomerController {

    @Autowired
    IBusCustomerService customerService;

    @Autowired
    IBusCustomerVisitService customerVisitService;

    @ApiOperation("保存客户")
    @PostMapping("/save")
    public R<Boolean> save(@RequestBody BusCustomer customer){
        Boolean result = customerService.saveDetail(customer);
        return R.success(result);
    }

    @ApiOperation("获取详情")
    @GetMapping("/getById")
    public R<BusCustomer> getById(String id){
        BusCustomer customer = customerService.getDetailById(id);
        return R.success(customer);
    }

    @ApiOperation("delById")
    @GetMapping("/delById")
    public R<Boolean> delById(String id){
        customerService.removeById(id);
        return R.success(true);
    }

    @GetMapping("/generatorCustomerNo")
    @ApiOperation("generatorCustomerNo")
    public R getCustomerNo(){
        String customerNo = customerService.generatorCustomerNo();
        return R.success(customerNo);
    }

    @PostMapping("/listByPage")
    @ApiOperation("listByPage")
    public R listByPage(@RequestBody CustomerListParamsVo vo){
        IPage<BusCustomer> page = customerService.listByPage(vo);
        return R.success(page);
    }

    @PostMapping("/saveVisit")
    @ApiOperation("saveVisit")
    public R saveVisit(@RequestBody BusCustomerVisit entity){
        customerVisitService.save(entity);
        return R.success(true);
    }

}

